package org.example.service;

import io.gitee.sunjx93.plugin.dataset.bean.annotation.SheetParam;
import io.gitee.sunjx93.plugin.dataset.bean.annotation.SheetResult;
import org.example.dto.DemoItem;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class DemoBeanService  {

    public List<DemoItem> listOne(@SheetParam("name") String name) {
        List<DemoItem> result = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            DemoItem d = new DemoItem();
            d.setAge(1);
            d.setName(name + "_" + i);
            d.setId(i);
            result.add(d);
        }
        return result;
    }

   public List<DemoItem> listMap(Map<String, Object> map) {
        List<DemoItem> result = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            DemoItem d = new DemoItem();
            d.setAge(Integer.parseInt((String) map.get("age")));
            d.setName(map.get("name") + "_" + i);
            d.setId(i);
            result.add(d);
        }
        return result;
    }

    public List<DemoItem> listParams(@SheetParam("name") String name,@SheetParam("age") int age) {
        List<DemoItem> result = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            DemoItem d = new DemoItem();
            d.setAge(age + i);
            d.setName(name + "_" + i);
            d.setId(i);
            result.add(d);
        }
        return result;
    }


    public List<DemoItem> listByParamItem(@SheetParam("name") String name,@SheetParam("item") DemoItem item) {
        List<DemoItem> result = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            DemoItem d = new DemoItem();
            d.setAge(item.getAge() + i);
            d.setName(item.getName() + "_" + i);
            d.setId(i);
            result.add(d);
        }
        return result;
    }

    @SheetResult(resultName = "result")
    public DemoStruct listItemResult(@SheetParam("name") String name,@SheetParam("item") DemoItem item) {
        DemoStruct struct = new DemoStruct();
        List<DemoItem> demoItems = listByParamItem(name, item);
        struct.setResult(demoItems);
        return struct;
    }


}

